#include <Functor.h>

enum EDialogResult
{
    eDialogResult_OK,
    eDialogResult_Cancel,
    eDialogResult_Preempted,
};

typedef FunctorTemplate<void, EDialogResult> DialogResultCallback;

class CSoundManager;

namespace AVUI
{
    class ResourceDictionary;
    class FrameworkElement;
    class Object;
    class Button;
    class RoutedEventArgs;
    class TextBox;
    class Window;
    class NavigationWindow;
}

class CUIManager
{
public:
    CUIManager(CSoundManager* pSoundManager);
    ~CUIManager();

    void ShowOKDialog(const WCHAR* wzMessage, DialogResultCallback dialogResultCallback);
    void ShowOKCancelDialog(const WCHAR* wzMessage, DialogResultCallback dialogResultCallback);
    void ShowCancelDialog(const WCHAR* wzMessage, DialogResultCallback dialogResultCallback);
    void EndCurrentDialog(EDialogResult eDialogResult);
    void ShowOptionsWindow();

    static AVUI::Button* CUIManager::FindButton(AVUI::FrameworkElement* pSceneRoot, const WCHAR* wzButtonName);
    static AVUI::TextBlock* CUIManager::FindTextBlock(AVUI::FrameworkElement* pSceneRoot, const WCHAR* wzTextBlockName);
    static AVUI::TextBox* CUIManager::FindTextBox(AVUI::FrameworkElement* pSceneRoot, const WCHAR* wzTextBlockName);
    static AVUI::ResourceDictionary* CUIManager::LoadXamlResources(const WCHAR* wzFile);
    static AVUI::FrameworkElement* CUIManager::LoadXamlScene(const WCHAR* wzFile);
private:
    static AVUI::Object* LoadXaml(const WCHAR* wzXamlFile);


    void OnOkClicked(AVUI::Object* pObject, AVUI::RoutedEventArgs* pArgs);
    void OnCancelClicked(AVUI::Object* pObject, AVUI::RoutedEventArgs* pArgs);
    void ShowOkCancelDialogCore(const WCHAR* wzMessage, DialogResultCallback dialogResultCallback);
    void EndCurrentDialogPostTransition(AVUI::Object* pSender, AVUI::EventArgs* pArgs);

    class CDialogResultCallbackHolder
    {
    public:
        CDialogResultCallbackHolder(const DialogResultCallback& dialogResultCallback) : m_dialogResultCallback(dialogResultCallback) { };
        const DialogResultCallback& GetDialogResultCallback() { return m_dialogResultCallback; }
    private:
        DialogResultCallback m_dialogResultCallback;
    };

    CDialogResultCallbackHolder* m_pDialogResultCallbackHolder;

    AVUI::Window* m_pOKCancelDialog;
    AVUI::FrameworkElement* m_pOKCancelDialogPage;
    EDialogResult m_eDeferredDialogResult;

    AVUI::NavigationWindow* m_pOptionsWindow;

    CSoundManager* m_pSoundManager;
};

